<?php

namespace App\Constants\Rbac;

class RouteCode
{

    public const TYPE_NAV = 1; // 菜单
    public const TYPE_WEB = 2; // WEB页面
    public const TYPE_BUTTON = 3; // 按钮
    public const TYPE_API = 4;   // API接口
//    public const TYPE_NODE = 5;   // 节点，树形结构的节点

    public const HEADER_CLIENT_OS = 'client-os';
    public const HEADER_CLIENT_VERSION = 'client-version';
    public const HEADER_FACE_TO = 'face-to';
    public const HEADER_TOKEN = 'w-token';

    public const CUSTOM_RULE_MUST_LOGIN_USER = 'mustLoginUser';
    public const CUSTOM_RULE_REAL_NAME_AUTH = 'realNameAuth';

    public const CUSTOM_RULE_MUST_LOGIN_ADMIN = 'mustLoginAdmin';
    public const CUSTOM_RULE_ADMIN_POWER_CHECK = 'adminPowerCheck';

    public const FACE_TO_ADMIN = 'admin';
    public const FACE_TO_MEMBER = 'member';

    public const RATE_LIMIT_BY_PATH = 'path';
    public const RATE_LIMIT_BY_PATH_IP = 'path_ip';
    public const RATE_LIMIT_BY_PATH_UID = 'path_uid';

    // 非用户维度的限制规则
    public static function visitorRateRule($input=null)
    {
        $arr = [
            self::RATE_LIMIT_BY_PATH,
            self::RATE_LIMIT_BY_PATH_IP,
        ];
        return $input ? in_array($input,$arr) : $arr;
    }

    public static function mustAdminLogin($rule=null)
    {
        $arr = [
            self::CUSTOM_RULE_MUST_LOGIN_ADMIN,
            self::CUSTOM_RULE_ADMIN_POWER_CHECK,
        ];
        return $rule ? in_array($rule,$arr) : $arr;
    }

    public static function mustUserLogin($rule=null)
    {
        $arr = [
            self::CUSTOM_RULE_MUST_LOGIN_USER,
            self::CUSTOM_RULE_REAL_NAME_AUTH,
        ];
        return $rule ? in_array($rule,$arr) : $arr;
    }

    public static function validType($input=null)
    {
        $arr = [
            self::TYPE_NAV,
            self::TYPE_WEB,
            self::TYPE_BUTTON,
            self::TYPE_API,
//            self::TYPE_NODE,
        ];
        return $input ? in_array($input,$arr) : $arr;
    }
}